package com.oa.action.user;

import java.util.List;

import com.oa.model.Person;
import com.oa.model.User;
import com.oa.service.user.UserService;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

public class UserAction extends ActionSupport implements Preparable{
	private List<User> users;
    private User user;
    private Integer id;
    private UserService userService;

    public UserAction(UserService userService) {
        this.userService = userService;
    }

    public String execute() {
        this.users = userService.findAll();
        return Action.SUCCESS;
    }

    public String save() {
        this.userService.save(user);
        this.user = new User();
        return execute();
    }

    public String remove() {
        userService.remove(id);
        return execute();
    }

    public List<User> getUsers() {
        return users;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public void prepare() throws Exception {
        if (id != null)
            user = userService.find(id);
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

}
